

import { action, observable, computed } from 'mobx';

import * as store from 'store';

//类型
export interface IUserStore {
    userInfo: any,
    isLogin: boolean;
    login(userInfo: any): void;
}



export const storeKey = "IUserInfo"
const userInfo = store.get(storeKey) || {};
export class UserStore implements IUserStore {


    @observable
    public userInfo: any = userInfo;

    @computed
    public get isLogin(): boolean {
        console.log(this.userInfo.username);
        return !!this.userInfo.username;
    }

    @action.bound
    public login(data: any): void {
        store.set(storeKey, data);
        this.userInfo = data;
    }
    
    @action.bound
    public loginOut() {
        store.remove(storeKey);
        this.userInfo = {};
    }
}